package cn.getech.data.metadata.controller;

import cn.getech.data.intelligence.common.utils.BaseRes;
import cn.getech.data.intelligence.common.utils.PageRes;
import cn.getech.data.intelligence.common.utils.PageUtils2;
import cn.getech.data.intelligence.common.validator.ValidatorUtils;
import cn.getech.data.intelligence.common.validator.group.AddGroup;
import cn.getech.data.intelligence.common.validator.group.UpdateGroup;
import cn.getech.data.metadata.model.req.collectiontableinfo.CollectionTableInfoUpdateReq;
import cn.getech.data.metadata.model.req.roledatapermission.CollectionTableRoleDataPermissionListReq;
import cn.getech.data.metadata.model.req.roledatapermission.CollectionTableRoleDataPermissionSaveInner;
import cn.getech.data.metadata.model.req.roledatapermission.CollectionTableRoleDataPermissionSaveReq;
import cn.getech.data.metadata.model.res.roledatapermission.CollectionTableRoleDataPermissionRes;
import cn.getech.data.metadata.service.CollectionTableRoleDataPermissionService;
import cn.getech.system.center.annotation.SysLog;
import cn.getech.system.center.constant.OperationModulesEnum;
import cn.getech.system.center.constant.OperationTypeEnum;
import cn.getech.system.center.constant.module.ModuleEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(value="元数据管理权限",tags={"元数据管理权限"})
@RestController
@RequestMapping("md/collectionTableRoleDataPermission")
public class CollectionTableRoleDataPermissionController {
    @Autowired
    private CollectionTableRoleDataPermissionService collectionTableRoleDataPermissionService;

    @ApiOperation("元数据权限列表")
    @PostMapping("/list")
    public PageRes<PageUtils2<CollectionTableRoleDataPermissionRes>> list(@RequestBody CollectionTableRoleDataPermissionListReq req){
        ValidatorUtils.validateEntity(req, AddGroup.class);
        PageUtils2<CollectionTableRoleDataPermissionRes> page = collectionTableRoleDataPermissionService.list(req);

        return BaseRes.okWithPage(page);
    }

    @ApiOperation("保存元数据权限")
    @PostMapping("/save")
    @SysLog(value="保存元数据权限",type= OperationTypeEnum.UPDATECODE, modulesType = OperationModulesEnum.DATAMETADATACODE,platformModuleType = ModuleEnum.METADATA_LIST_MODULE_CODE)
    public BaseRes save(@RequestBody CollectionTableRoleDataPermissionSaveReq req){
        ValidatorUtils.validateEntity(req, AddGroup.class);
        for(CollectionTableRoleDataPermissionSaveInner inner : req.getPermissioins()){
            ValidatorUtils.validateEntity(inner, AddGroup.class);
        }

        collectionTableRoleDataPermissionService.save(req);

        return BaseRes.ok();
    }
}
